package com.ruoyi.web.controller.disasterAssessment;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.disasterassessment.domain.DisasterAssessment;
import com.ruoyi.disasterassessment.service.IDisasterAssessmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 安全评估时间Controller
 * 
 * @author hcc
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/disasterassessment/assessment")
public class DisasterAssessmentController extends BaseController
{
    @Autowired
    private IDisasterAssessmentService disasterAssessmentService;

    /**
     * 查询安全评估时间列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessment:list')")
    @GetMapping("/list")
    public TableDataInfo list(DisasterAssessment disasterAssessment)
    {
        startPage();
        List<DisasterAssessment> list = disasterAssessmentService.selectDisasterAssessmentList(disasterAssessment);
        return getDataTable(list);
    }

    /**
     * 导出安全评估时间列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessment:export')")
    @Log(title = "安全评估时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DisasterAssessment disasterAssessment)
    {
        List<DisasterAssessment> list = disasterAssessmentService.selectDisasterAssessmentList(disasterAssessment);
        ExcelUtil<DisasterAssessment> util = new ExcelUtil<DisasterAssessment>(DisasterAssessment.class);
        util.exportExcel(response, list, "安全评估时间数据");
    }

    /**
     * 获取安全评估时间详细信息
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(disasterAssessmentService.selectDisasterAssessmentById(id));
    }

    /**
     * 新增安全评估时间
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessment:add')")
    @Log(title = "安全评估时间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DisasterAssessment disasterAssessment)
    {
        return toAjax(disasterAssessmentService.insertDisasterAssessment(disasterAssessment));
    }

    /**
     * 修改安全评估时间
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessment:edit')")
    @Log(title = "安全评估时间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DisasterAssessment disasterAssessment)
    {
        return toAjax(disasterAssessmentService.updateDisasterAssessment(disasterAssessment));
    }

    /**
     * 删除安全评估时间
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:assessment:remove')")
    @Log(title = "安全评估时间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(disasterAssessmentService.deleteDisasterAssessmentByIds(ids));
    }
}
